
import 'dart:convert';

import 'package:animated_tree_view/animated_tree_view.dart' as treeview;
import 'package:data_table_2/data_table_2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_switch/flutter_switch.dart';
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:yuellyfactory/util/AuthUtil.dart';
import 'package:yuellyfactory/util/GlobalData.dart';
import 'package:yuellyfactory/util/MathUtil.dart';
import '../../components/NoScrollbarBehavior.dart';
import '../../eventbus/EventBusUtil.dart';
import '../../eventbus/EventRefreshBase.dart';
import '../../util/BaseRequest.dart';
import '../../util/ColorUtil.dart';
import '../../util/ToastUtil.dart';
import '../../util/ViewUtil.dart';
import '../../util/XNumberTextInputFormatter.dart';
import '../dto/PriceParm.dart';
import '../dto/PricePart.dart';
import '../dto/PriceRule.dart';
import '../dto/Supplier.dart';


class MaterialEditVC extends StatefulWidget {

  final VoidCallback callback;
  final PricePart pricePart;
  const MaterialEditVC({super.key, required this.callback, required this.pricePart});

  @override
  State<MaterialEditVC> createState() => _MaterialEditVCState();
}

class _MaterialEditVCState extends State<MaterialEditVC> {


  final popoverController = ShadPopoverController();
  final formKey = GlobalKey<ShadFormState>();
  var specsList=[];

  var priceList=[];

  String supplierId="";


  final dialogKey = GlobalKey<ShadFormState>();

  PricePart pricePart=PricePart();
  PricePart parmPart=PricePart();
  Map parmValues={};
  Map remarkValues={};
  String ruleStr="";

  List allDatas=[];
  treeview.TreeViewController? _controller;
  var sampleTree = treeview.TreeNode.root();

  PricePart selectPricePart=PricePart();
  Map hasSelect={};

  List<String> hasSelectIds=[];


  String priceStr="0";

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    if(widget.pricePart.spec.isNotEmpty){
      specsList=jsonDecode(widget.pricePart.spec);
    }
    if(widget.pricePart.priceConfig.isNotEmpty){
      priceList=jsonDecode(widget.pricePart.priceConfig);
    }
    ruleStr=widget.pricePart.rule;
    pricePart=widget.pricePart;
    supplierId=widget.pricePart.supplierId;
    priceStr=widget.pricePart.dPrice.toString();
    if(pricePart.parmData.isNotEmpty){
      List list=jsonDecode(pricePart.parmData);
      for(var item in list){
        parmValues[item["name"]]=item["value"];
      }
    }
    if(pricePart.remarkData.isNotEmpty){
      List list=jsonDecode(pricePart.remarkData);
      for(var item in list){
        remarkValues[item["name"]]=item["value"];
      }
    }
    getAllSupplier();
    getParms();
    if(widget.pricePart.typeId==GlobalData.compressorId){
      initSelectData();
      getAllData();
    }
  }

  void getParms(){
    BaseRequest.postHttp('price/typeparmbyid',parameters: {"id":widget.pricePart.parentId}, canTip: false, context: context, onSuccess: (data){
      dynamic datas=data["data"];
      var part=PricePart.fromJson(datas);
      parmPart=part;
      setState(() {

      });
    }, onError: (error){});
  }

  @override
  void dispose() {

    super.dispose();
  }
  @override
  Widget build(BuildContext context) {
    return
      ShadSheet(
        onClosing: (){
          widget.callback();
        },
        constraints: const BoxConstraints(minWidth: 1200,maxWidth: 1200),
        title: Row(
          children: [
            const Text('该系列下属型号编辑'),
            const SizedBox(width: 50,),
            ViewUtil.doneIcon("保存", (){
              save();
            })
          ],

        ),




        child: ShadForm(
          key: formKey,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: [

              Visibility(
                  visible: true,
                  child: Row(children: [
                Expanded(child:  ShadInputFormField(
                  id: 'name',
                  initialValue: pricePart!.name,
                  label: const Text('型号名称'),
                  placeholder: const Text('请输入型号名称'),
                  validator: (v) {
                    if (v.isEmpty) {
                      return '请输入型号名称';
                    }
                    return null;
                  },
                ),),
                const SizedBox(width: 10),
                Expanded(child: ShadInputFormField(
                  id: 'code',
                  label: const Text('Code'),
                  initialValue: pricePart!.code,
                  placeholder: const Text('请输入Code'),
                  validator: (v) {
                    if (v.isEmpty) {
                      return '请输入Code';
                    }
                    return null;
                  },
                ),)
              ],))
              ,
              const SizedBox(height: 16),
              Visibility(
                  visible: true,
                  child:  Row(
                children: [


                  Expanded(child: ShadInputFormField(
                    id: 'tax',
                    label: const Text('税点(如8%,则填写0.08）'),
                    suffix: const Text('%'),
                    initialValue: MathUtil.formatDouble(double.parse(pricePart!.tax), 2),
                    placeholder: const Text('请输入税点'),
                    validator: (v) {
                      if (v.isEmpty) {
                        return '请输入税点';
                      }
                      return null;
                    },
                  ),),
                  const SizedBox(width: 10),
                  Visibility(
                      visible: widget.pricePart.typeId==GlobalData.condenserId||widget.pricePart.typeId==GlobalData.evaporator,
                      child: Expanded(child: ShadInputFormField(
                    id: 'area1',
                    label: const Text('换热面积'),

                    initialValue: pricePart!.area1,
                    placeholder: const Text('请输入换热面积'),
                  ))),

                  Visibility(
                      visible: widget.pricePart.typeId==GlobalData.fluorineId,
                      child: Expanded(child: ShadInputFormField(
                    id: 'weight1',
                    label: const Text('铜配重量'),

                    initialValue: pricePart!.weight1,
                    placeholder: const Text('请输入铜配重量'),
                  ),)),

                  Visibility(
                      visible: widget.pricePart.typeId!=GlobalData.fluorineId&&widget.pricePart.typeId!=GlobalData.condenserId&&widget.pricePart.typeId!=GlobalData.evaporator,
                      child: Expanded(child: Container())),

                ],

              ))
             ,

              if(widget.pricePart.typeId==GlobalData.compressorId)
              const SizedBox(height: 10),
              Visibility(
                  visible: widget.pricePart.typeId==GlobalData.compressorId,//是压缩机类型
                  child:  Row(
                    children: [
                      Expanded(child:Row(
                        children: [
                          const Text('建议换热面积',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 200,child: ShadInputFormField(
                            id: 'area1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.area1,
                            placeholder: Text('请输入最低换热面积',style: TextStyle(fontSize: ViewUtil.fontSize(20)),),

                          ),),
                          SizedBox(width: 200,child: ShadInputFormField(
                            id: 'area2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.area2,
                            placeholder: Text('请输入最高换热面积',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],

                      ),),
                      const SizedBox(width: 10),
                      Expanded(child: Row(
                        children: [
                          const Text('建议铜配重量',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 200,child: ShadInputFormField(
                            id: 'weight1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.weight1,
                            placeholder:  Text('请输入最低铜配重量',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),),
                          SizedBox(width: 200,child: ShadInputFormField(
                            id: 'weight2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.weight2,
                            placeholder:  Text('请输入最高铜配重量',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],
                      ),)
                    ],
                  )),




                const SizedBox(height: 10),

              Visibility(
                  visible: true,//是压缩机类型
                  child:  Row(
                    children: [
                      Expanded(child:Row(
                        children: [
                          const Text('S系列',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 's1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.s1,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最小值',style: TextStyle(fontSize: ViewUtil.fontSize(20)),),

                          ),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 's2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.s2,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最大值',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],
                      ),
                      ),
                      Expanded(child:Row(
                        children: [
                          const Text('H系列',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'h1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.h1,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最小值',style: TextStyle(fontSize: ViewUtil.fontSize(20)),),

                          ),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'h2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.h2,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最大值',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],
                      ),
                      ),

                      Expanded(child:Row(
                        children: [
                          const Text('E系列',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'e1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.e1,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最小值',style: TextStyle(fontSize: ViewUtil.fontSize(20)),),

                          ),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'e2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.e2,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最大值',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],
                      ),
                      ),

                      Expanded(child:Row(
                        children: [
                          const Text('W系列',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'w1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.w1,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最小值',style: TextStyle(fontSize: ViewUtil.fontSize(20)),),

                          ),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'w2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.w2,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最大值',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],
                      ),
                      ),

                    ],
                  )),



              Visibility(
                  visible: true,//是压缩机类型
                  child:  Row(
                    children: [
                      Expanded(child:Row(
                        children: [
                          const Text('D系列',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'd1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.d1,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最小值',style: TextStyle(fontSize: ViewUtil.fontSize(20)),),

                          ),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'd2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.d2,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最大值',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],
                      ),
                      ),
                      Expanded(child:Row(
                        children: [
                          const Text('C系列',style: TextStyle(color: Colors.black),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'c1',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.c1,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最小值',style: TextStyle(fontSize: ViewUtil.fontSize(20)),),

                          ),),
                          SizedBox(width: 100,child: ShadInputFormField(
                            id: 'c2',
                            placeholderAlignment: Alignment.centerLeft,
                            initialValue: pricePart!.c2,
                            keyboardType: TextInputType.numberWithOptions(decimal: false),
                            inputFormatters: [
                              FilteringTextInputFormatter.allow(RegExp("[0-9]")),
                              XNumberTextInputFormatter(
                                  maxIntegerLength: null,
                                  maxDecimalLength: 0,
                                  isAllowDecimal: false),
                            ],
                            placeholder: Text('最大值',style: TextStyle(fontSize: ViewUtil.fontSize(20))),
                          ),)
                        ],
                      ),
                      ),

                      Expanded(child:Row(
                        children: [
                        ],
                      ),
                      ),

                      Expanded(child:Row(
                        children: [
                        ],
                      ),
                      ),

                    ],
                  )),



              if(AuthUtil.instance.checkMenuBtn(AuthUtil.Base_Price))
              const SizedBox(height: 10),

              if(AuthUtil.instance.checkMenuBtn(AuthUtil.Base_Price))
              Row(
                children: [
                  Text('单价',style: TextStyle(color: Colors.black,  fontSize: ViewUtil.fontSize(22)),),
                  Expanded(child: Container()),
                  ViewUtil.addIcon('新增单价',(){
                    showPriceDialog({"id":"","price":""});
                  }),

                ],
              ),
              if(AuthUtil.instance.checkMenuBtn(AuthUtil.Base_Price))
              priceView(),



              //
              // Visibility(
              //   visible: false,
              //   child:  Text('型号概况',style: TextStyle(color: Colors.black,  fontSize: ViewUtil.fontSize(22)),),),
              //
              // Visibility(
              //   visible: false,
              //   child:  Wrap(
              //   crossAxisAlignment: WrapCrossAlignment.center,
              //   runAlignment: WrapAlignment.start,
              //   direction: Axis.horizontal, // 水平方向排列（默认）
              //   alignment: WrapAlignment.start, // 水平靠左（默认值，可省略）
              //   spacing: 10, // 子组件横向间距
              //   runSpacing: 0, // 换行后纵向间距
              //   children: getRemarkViews(),
              // ),),
              //
              // Visibility(
              //   visible: false,
              //   child:  Text('型号参数',style: TextStyle(color: Colors.black,  fontSize: ViewUtil.fontSize(22)),),),
              //
              // Visibility(
              //   visible: false,
              //   child:  Wrap(
              //   crossAxisAlignment: WrapCrossAlignment.center,
              //   runAlignment: WrapAlignment.start,
              //   direction: Axis.horizontal, // 水平方向排列（默认）
              //   alignment: WrapAlignment.start, // 水平靠左（默认值，可省略）
              //   spacing: 10, // 子组件横向间距
              //   runSpacing: 0, // 换行后纵向间距
              //   children: getParmsViews(),
              // ),),

              const SizedBox(height: 10),
              Visibility(
                visible: true,
                child: Row(
                children: [
                  Text('型号说明',style: TextStyle(color: Colors.black,  fontSize: ViewUtil.fontSize(22)),),

                  Expanded(child: Container()),
                  ViewUtil.addIcon('新增型号说明',(){
                    showSpecDialog({"name":"","value":""});
                  }),

                ],
              ),),


              const SizedBox(height: 10),
              Visibility(
                  visible: true,
                  child:  specView())
             ,
              const SizedBox(height: 16),
              // if(widget.pricePart.typeId==GlobalData.compressorId)
              //   Text('默认机型配置',style: TextStyle(color: Colors.black,  fontSize: ViewUtil.fontSize(22)),),
              // if(widget.pricePart.typeId==GlobalData.compressorId)
              //   Container(
              //     height: 500,
              //     child:  ClipRRect(
              //       child: ShadResizablePanelGroup(
              //         children: [
              //           ShadResizablePanel(
              //
              //             defaultSize: .5,
              //             minSize: .2,
              //             maxSize: .5,
              //             child: ShadResizablePanelGroup(
              //               axis: Axis.horizontal,
              //               children: [
              //                 ShadResizablePanel(
              //                   defaultSize: .6,
              //                   minSize: .4,
              //                   maxSize: .7,
              //                   child: Column(
              //                     crossAxisAlignment: CrossAxisAlignment.start,
              //                     children: [
              //                       Expanded(
              //                         child: Card( color: Colors.white,
              //                           child:
              //                           ScrollConfiguration(
              //                             behavior: NoScrollbarBehavior(),
              //                             child: SingleChildScrollView(
              //                               child:
              //                               Padding(
              //                                 padding: const EdgeInsets.all(5.0),
              //                                 child:
              //                                 Column(
              //                                   crossAxisAlignment: CrossAxisAlignment.start,
              //                                   children: [
              //                                     SizedBox(height: ViewUtil.screenWidth(10),),
              //                                     Text('已选配置',style: TextStyle(fontSize: ViewUtil.fontSize(20),fontWeight: FontWeight.bold),),
              //                                     SizedBox(height: ViewUtil.screenWidth(10),width: double.infinity,),
              //                                     Column(
              //                                       crossAxisAlignment: CrossAxisAlignment.start,
              //                                       children: getAllSelectData(),
              //                                     )
              //                                   ],
              //                                 )
              //
              //
              //                                 ,
              //                               ),),
              //                           ),
              //
              //                         ),
              //                       ),
              //                     ],
              //                   ),
              //
              //                 ),
              //                 ShadResizablePanel(
              //                   defaultSize: .4,
              //                   minSize: .3,
              //                   maxSize: .6,
              //                   child:
              //                   Card(
              //                       color: Colors.white,
              //                       child:Column(
              //                         mainAxisSize: MainAxisSize.min,
              //                         children: [
              //                           SizedBox(height: ViewUtil.screenHeight(10),),
              //
              //                           // SizedBox(height: ViewUtil.screenHeight(10),),
              //                           Expanded(child:
              //                           treeview.TreeView.simple(
              //                               showRootNode: false,
              //                               focusToNewNode: false,
              //                               expansionIndicatorBuilder: (context, node) {
              //                                 return treeview.ChevronIndicator.rightDown(
              //                                     tree: node,
              //                                     alignment: Alignment.centerRight,
              //                                     //color: Colors.grey[700],
              //                                     color:ColorUtil.colorBlue
              //                                 );
              //                               },
              //                               indentation: const treeview.Indentation(
              //                                   style: treeview.IndentStyle.roundJoint),
              //                               onItemTap: (item) {
              //                                 print("Item tapped: ${item.key}");
              //                                 selectPricePart=item.data;
              //                                 setState(() {
              //
              //                                 });
              //                               },
              //                               onTreeReady: (controller) {
              //                                 _controller = controller;
              //                               },
              //                               builder: (context, node) =>  Container(
              //                                 decoration: BoxDecoration(
              //                                   color: selectPricePart.id==node.key ? Colors.blue.withOpacity(0.1) : null,
              //                                   borderRadius: BorderRadius.circular(4),
              //                                 ),
              //                                 child: ListTile(
              //                                   title: Text("${node.data.name}",style: TextStyle(fontSize: ViewUtil.fontSize(20)),),
              //                                   trailing:  !hasSelectIds.contains(node.data.id)&&node.data.type=='type'?
              //
              //                                   const Icon(Icons.circle,color: Colors.red,size: 12,)
              //                                       :null,
              //
              //                                 ),
              //                               ),
              //                               tree: sampleTree),)
              //
              //                         ],
              //                       )
              //
              //                   ),
              //                 ),
              //               ],
              //             ),
              //           ),
              //
              //
              //           ShadResizablePanel(
              //             defaultSize: .5,
              //             child:
              //             Column(
              //               crossAxisAlignment: CrossAxisAlignment.start,
              //               children: [
              //                 Expanded(
              //                   child: Card( color: Colors.white,
              //                     child:
              //                     ScrollConfiguration(
              //                       behavior: NoScrollbarBehavior(),
              //                       child: SingleChildScrollView(
              //                         child:
              //                         Padding(
              //                           padding: const EdgeInsets.all(5.0),
              //                           child:
              //                           Column(
              //                             children: [
              //                               SizedBox(height: ViewUtil.screenWidth(10),),
              //                               Row(
              //                                 children: [
              //                                   SizedBox(width: ViewUtil.screenWidth(10),),
              //                                   Expanded(child: Text(selectPricePart.name,
              //                                     style: TextStyle(fontSize: ViewUtil.fontSize(20),fontWeight: FontWeight.bold)
              //                                     ,),),
              //
              //                                 ],
              //                               ),
              //                               if(selectPricePart.type=='serial')
              //                                 allPartWidgets()
              //                             ],
              //                           )
              //
              //
              //                           ,
              //                         ),),
              //                     ),
              //
              //                   ),
              //                 ),
              //               ],
              //             ),
              //           ),
              //         ],
              //       ),
              //     ),
              //
              //
              //   ),
              //
              // const SizedBox(height: 16),


              // Row(
              //   children: [
              //     Text('参数',style: TextStyle(color: Colors.black,  fontSize: ViewUtil.fontSize(22)),),
              //     Expanded(child: Container()),
              //     ViewUtil.editIcon((){
              //       showShadSheet(
              //         barrierColor: Colors.transparent,
              //         side: ShadSheetSide.right,
              //         context: context,
              //         builder: (context) =>  MaterialParmVC(pricePart:pricePart! , callback: () {
              //           //回调
              //           //getDetail();
              //         },),
              //       );
              //     }),
              //
              //   ],
              // ),
              // ViewUtil.lineView(),
              // const SizedBox(height: 16),
              // Row(
              //   children: [
              //     Text('零件',style: TextStyle(color: Colors.black,  fontSize: ViewUtil.fontSize(22)),),
              //     Expanded(child: Container()),
              //     ViewUtil.editIcon((){
              //       showShadSheet(
              //         barrierColor: Colors.transparent,
              //         side: ShadSheetSide.right,
              //         context: context,
              //         builder: (context) =>   MaterialListVC(pricePart:pricePart! , callback: () {
              //           //回调
              //          // getDetail();
              //         },),
              //       );
              //     }),
              //
              //   ],
              // ),
              // ViewUtil.lineView(),
              // const SizedBox(height: 16),
              // Row(
              //   children: [
              //     Text('单价计算公式(有零件则使用零件累加计算)',style: TextStyle(color: Colors.black, fontSize: ViewUtil.fontSize(22)),),
              //     Expanded(child: Container()),
              //     ViewUtil.editIcon((){
              //       showShadSheet(
              //         barrierColor: Colors.transparent,
              //         side: ShadSheetSide.right,
              //         context: context,
              //         builder: (context) =>  RuleVC(pricePart:pricePart! , callback: () {
              //           //回调
              //           getDetail();
              //         },),
              //       );
              //     }),
              //
              //   ],
              // ),
              // Card(
              //     color: Colors.white,
              //     child:
              //     Container(
              //       padding: const EdgeInsets.only(left: 10,right: 10,top: 5,bottom: 5),
              //       alignment: Alignment.centerLeft,
              //       child: Text(getRuleString(ruleStr),style: const TextStyle(fontSize: 20),),
              //     )),



            ],

          ),

        ),
      );
  }


  List<Widget> getRemarkViews(){
    List<Widget> widgets=[];
    for(PriceParm parm in parmPart.remarkList){
      List selectItems=[];
      if(parm.rule.isNotEmpty){
        List list=jsonDecode(parm!.rule);
        for (var item in list) {
          selectItems.add(item.toString());
        }
      }
      var initValue="";
      if(remarkValues.containsKey(parm.id)){
        initValue=remarkValues[parm.id];
      }else{
        if(parm.value.isNotEmpty){
          initValue=parm.value;
        }
      }

      parm.value=initValue;
      widgets.add(
          SizedBox(width: 220,
              child:
              Row(children: [
                Text("${parm.name}:"),
                if(parm.type==0)
                  Expanded(child: ShadInput(
                    suffix: Text(parm.unit??""),
                    textAlign: TextAlign.end,
                    initialValue:initValue,
                    placeholder: Text("请输入${parm.name}"),
                    onChanged: (value){
                      debugPrint(value);
                      parm.value=value;
                    },
                  )),
                if(parm.type==1)
                  Expanded(child:  ShadSelect<String>(
                    minWidth: 350,
                    onChanged: (value){
                      if (value != null && parm != null) {  // 增加parm的空判断
                        parm.value = value;  // 移除不必要的toString()
                      }
                    },
                    initialValue: initValue,
                    options: selectItems.map((item) {
                      final value = item.isNotEmpty ? item : '';
                      return ShadOption<String>(
                        value: value,
                        child: Text(value),
                      );
                    }).toList(),
                    selectedOptionBuilder: (context, value) {
                      // 处理value可能为null的情况
                      if (value == null || value.isEmpty || value == 'none') {
                        return const Text('请选择');
                      }
                      return Text(value);
                    },
                    placeholder: const Text('请选择'),

                  ),),

              ],)));
    }
    return widgets;
  }


  List<Widget> getParmsViews(){
    List<Widget> widgets=[];
    for(PriceParm parm in parmPart.partParmList){
      List selectItems=[];
      if(parm.rule.isNotEmpty){
        List list=jsonDecode(parm!.rule);
        for (var item in list) {
          selectItems.add(item.toString());
        }
      }
      var initValue="";
      if(parmValues.containsKey(parm.id)){
        initValue=parmValues[parm.id];
      }else{
        if(parm.value.isNotEmpty){
          initValue=parm.value;
        }
      }

      parm.value=initValue;
      widgets.add(
          SizedBox(width: 220,
              child:
              Row(children: [
                Text("${parm.name}:"),
                if(parm.type==0)
                  Expanded(child: ShadInput(
                    suffix: Text(parm.unit??""),
                    textAlign: TextAlign.end,
                    initialValue:initValue,
                    placeholder: Text("请输入${parm.name}"),
                    onChanged: (value){
                      debugPrint(value);
                      parm.value=value;
                    },
                  )),
                if(parm.type==1)
                  Expanded(child:  ShadSelect<String>(
                    minWidth: 350,
                    onChanged: (value){
                      if (value != null && parm != null) {  // 增加parm的空判断
                        parm.value = value;  // 移除不必要的toString()
                      }
                    },
                    initialValue: initValue,
                    options: selectItems.map((item) {
                      final value = item.isNotEmpty ? item : '';
                      return ShadOption<String>(
                        value: value,
                        child: Text(value),
                      );
                    }).toList(),
                    selectedOptionBuilder: (context, value) {
                      // 处理value可能为null的情况
                      if (value == null || value.isEmpty || value == 'none') {
                        return const Text('请选择');
                      }
                      return Text(value);
                    },
                    placeholder: const Text('请选择'),

                  ),),

              ],)));
    }
    return widgets;
  }


  getRuleString(var rule){
    var ruleStr="";
    if(rule.isNotEmpty){
      List<dynamic> list = json.decode(rule);

      for(var item in list){
        PriceRule rule=PriceRule.fromJson(item);
        if(rule.handle==0){
          ruleStr="$ruleStr${rule.value}";
        }else{
          ruleStr="$ruleStr${rule.name}";
        }
      }
    }
    if(ruleStr.isEmpty)ruleStr="未设置";

    return ruleStr;
  }


  Widget specView(){
    final double tableHeight = _calculateTableHeight(specsList.length);
    return // 表格（高度固定为计算值）
      Padding(
        padding: EdgeInsets.symmetric(horizontal: _outerPadding),
        child: Container(
          // 应用计算出的高度
          height: tableHeight,
          decoration: BoxDecoration(
            border: Border.all(color: Colors.grey[200]!, width: _borderWidth),
            borderRadius: BorderRadius.circular(8),
          ),
          child: DataTable2(
            columnSpacing: 12,
            //  minWidth: MediaQuery.of(context).size.width - 2 * _outerPadding,
            minWidth: 500,
            headingRowHeight: _headerHeight - 2 * _borderWidth, // 减去边框占用高度
            dataRowHeight: _rowHeight - 2 * _borderWidth, // 减去边框占用高度
            // 表头
            columns: const [
              DataColumn2(
                label: Text('  操作'),
                fixedWidth: 140,
              ),
              DataColumn2(
                label: Text('名称'),
                size: ColumnSize.L,

              ),
              DataColumn2(
                label: Text('参数'),
                size: ColumnSize.L,
              ),
            ],

            // 表格内容（行高固定）
            rows: specsList.map((item) {
              return DataRow(cells: [
                DataCell(
                  Row(
                    children: [

                      ViewUtil.editIcon('编辑规格',(){showSpecDialog(item);}),

                      ViewUtil.delIcon('删除规格',(){
                        specsList.remove(item);
                        setState(() {

                        });
                      }),

                    ],
                  ),
                ),
                DataCell(Padding(
                  padding: const EdgeInsets.symmetric(vertical: 12),
                  child: Text(item["name"]),
                )),

                DataCell(Padding(
                  padding: const EdgeInsets.symmetric(vertical: 12),
                  child: Text(item["value"]),
                )),

              ]);
            }).toList(),
          ),
        ),
      );
  }


  Widget priceView(){
    final double tableHeight = _calculateTableHeight(priceList.length);
    return // 表格（高度固定为计算值）
      Padding(
        padding: EdgeInsets.symmetric(horizontal: _outerPadding),
        child: Container(
          // 应用计算出的高度
          height: tableHeight,
          decoration: BoxDecoration(
            border: Border.all(color: Colors.grey[200]!, width: _borderWidth),
            borderRadius: BorderRadius.circular(8),
          ),
          child: DataTable2(
            columnSpacing: 12,
            //  minWidth: MediaQuery.of(context).size.width - 2 * _outerPadding,
            minWidth: 500,
            headingRowHeight: _headerHeight - 2 * _borderWidth, // 减去边框占用高度
            dataRowHeight: _rowHeight - 2 * _borderWidth, // 减去边框占用高度
            // 表头
            columns: const [
              DataColumn2(
                label: Text('  操作'),
                fixedWidth: 180,
              ),
              DataColumn2(
                label: Text('公司名称'),
                size: ColumnSize.L,

              ),
              DataColumn2(
                label: Text('联系人'),


              ),
              DataColumn2(
                label: Text('联系电话'),


              ),
              DataColumn2(
                label: Text('单价(元)'),
                size: ColumnSize.L,
              ),
            ],

            // 表格内容（行高固定）
            rows: priceList.map((item) {
              return DataRow(cells: [
                DataCell(
                  Row(
                    children: [
                      ShadCheckbox(
                        value: item["id"]==supplierId,
                        size: 18,
                        decoration: ShadDecoration(border: ShadBorder.all(color:ColorUtil.colorBlue ),),
                        color: ColorUtil.colorBlue,
                        onChanged: (v) => {
                          if(v){
                            setState(() {
                              supplierId=item["id"];
                              priceStr=item["price"];
                            })
                          }else{
                            setState(() {
                              supplierId="";
                              priceStr="0";
                            })
                          }


                        },
                      ),
                      ViewUtil.editIcon('编辑单价',(){showPriceDialog(item);}),

                      ViewUtil.delIcon('删除单价',(){
                        if(item["id"]==supplierId){
                          supplierId="";
                          priceStr="0";
                        }
                        priceList.remove(item);
                        setState(() {

                        });
                      }),

                    ],
                  ),
                ),
                DataCell(Padding(
                  padding: const EdgeInsets.symmetric(vertical: 12),
                  child: Text(GlobalData.allSupplier[item["id"]]!.company),
                )),
                DataCell(Padding(
                  padding: const EdgeInsets.symmetric(vertical: 12),
                  child: Text(GlobalData.allSupplier[item["id"]]!.name),
                )),
                DataCell(Padding(
                  padding: const EdgeInsets.symmetric(vertical: 12),
                  child: Text(GlobalData.allSupplier[item["id"]]!.cellphone),
                )),

                DataCell(Padding(
                  padding: const EdgeInsets.symmetric(vertical: 12),
                  child: Text(item["price"]),
                )),

              ]);
            }).toList(),
          ),
        ),
      );
  }






  // 固定高度参数（可根据需求调整）
  final double _headerHeight = 56; // 表头高度（含内边距）
  final double _rowHeight = 48; // 每行高度（含内边距）
  final double _borderWidth = 1; // 边框宽度
  final double _outerPadding = 10; // 表格外间距

  // 计算表格总高度的核心方法
  double _calculateTableHeight(int length) {
    // 总高度 = 表头高度 + 数据行总高度 + 边框总高度
    // 边框高度：上下边框（2条）+ 行之间的分隔线（数据行数-1条）
    final int borderCount = 2 + (length - 1);
    final double totalBorderHeight = borderCount * _borderWidth;

    return _headerHeight + // 表头高度
        (_rowHeight * length) + // 所有数据行高度
        totalBorderHeight; // 边框总高度
  }


  void showPriceDialog(var item){

    Map<String,Supplier> suppliers={};
    List<String> hasAdd=[];
    for(var item in priceList){
      hasAdd.add(item["id"]);
    }
    for(String key in GlobalData.allSupplier.keys){
      if(!hasAdd.contains(key)){
        suppliers[key]=GlobalData.allSupplier[key]!;
      }

      if(item["id"].length>0){
        if(item["id"]==key){
          suppliers[key]=GlobalData.allSupplier[key]!;
        }
      }
    }
    if(suppliers.isEmpty){
      ToastUtil.showToast("请先添加新的供应商");
      return;
    }

    showShadDialog(context: context, builder: (context)=>
        ShadDialog(
            actions: [ShadButton(child: const Text('确定'),onPressed: (){
              if (dialogKey.currentState!.saveAndValidate()) {
                var values = dialogKey.currentState!.value;
                var price=values["price"];
                var id=values["id"];
                if(item["id"].length==0){
                  item["id"]=id;
                  item["price"]=price;
                  priceList.add(item);
                  if(priceList.length==1){
                    supplierId=id;
                    priceStr=price;
                  }
                }else{
                  item["id"]=id;
                  item["price"]=price;
                }
                setState(() {
                });
                Navigator.pop(context);
              }
            },)],
            child:
            ShadForm(
              key: dialogKey,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  ShadSelectFormField<String>(
                    id: 'id',
                    label: const Text('供应商'),
                    minWidth: 600,
                    initialValue: item["id"],
                    options:[...suppliers.entries
                        .map((e) => ShadOption(value: e.key, child: Text(e.value.company))),],
                    selectedOptionBuilder: (context, value) => value == 'none'
                        ? const Text('请选择供应商')
                        : value.isNotEmpty?Text(GlobalData.allSupplier[value]!.company):const Text(""),
                    placeholder: const Text('请选择供应商'),
                    validator: (v) {
                      if (v == null||v.length==0) {
                        return '请选择供应商';
                      }
                      return null;
                    },
                  ),
                  const SizedBox(height: 16),
                  SizedBox(width: 600,child:ShadInputFormField(
                    id: 'price',
                    keyboardType: TextInputType.numberWithOptions(decimal: true),
                    inputFormatters: [
                      FilteringTextInputFormatter.allow(RegExp("[0-9.]")),
                      XNumberTextInputFormatter(
                          maxIntegerLength: null,
                          maxDecimalLength: 2,
                          isAllowDecimal: true),
                    ],
                    initialValue: item["price"],
                    label: const Text('单价'),
                    placeholder: const Text('请输入单价'),
                    validator: (v) {
                      if (v.isEmpty) {
                        return '请输入单价';
                      }
                      return null;
                    },
                  ) ,)



                ],
              )

              ,)

        )
    );
  }

  void showSpecDialog(var item){
    showShadDialog(context: context, builder: (context)=>
        ShadDialog(
            actions: [ShadButton(child: const Text('确定'),onPressed: (){
              if (dialogKey.currentState!.saveAndValidate()) {
                var values = dialogKey.currentState!.value;
                var name=values["name"];
                var value=values["value"];
                if(item["name"].length==0){
                  item["name"]=name;
                  item["value"]=value;
                  specsList.add(item);

                }else{
                  item["name"]=name;
                  item["value"]=value;
                }
                setState(() {

                });
                Navigator.pop(context);
              }
            },)],
            child:
            ShadForm(
              key: dialogKey,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  ShadInputFormField(
                    id: 'name',
                    initialValue: item["name"],
                    label: const Text('规格名称'),
                    placeholder: const Text('请输入规格名称'),
                    validator: (v) {
                      if (v.isEmpty) {
                        return '请输入规格名称';
                      }
                      return null;
                    },
                  ),
                  const SizedBox(height: 16),
                  ShadInputFormField(
                    id: 'value',
                    initialValue: item["value"],
                    label: const Text('规格'),
                    placeholder: const Text('请输入规格'),
                    validator: (v) {
                      if (v.isEmpty) {
                        return '请输入规格';
                      }
                      return null;
                    },
                  )


                ],
              )

              ,)

        )
    );
  }


  void save(){
    if (formKey.currentState!.saveAndValidate()) {

      // if(specsList.isEmpty){
      //   ToastUtil.showToast("请添加规格");
      //   return;
      // }

      bool result=true;
       var remarkDatas=[];
      for(PriceParm parm in parmPart.remarkList){
        var value=parm.value;
        // if(parm.required==1&&value.isEmpty){
        //   // result=false;
        //   // if(parm.type==0){
        //   //   ToastUtil.showToast('请输入${parm.name}');
        //   // }else{
        //   //   ToastUtil.showToast('请选择${parm.name}');
        //   // }
        //   //
        //   // break;
        // }else{
        //   remarkDatas.add({"name":parm.id,"value":value});
        // }
        remarkDatas.add({"name":parm.id,"value":value});
      }
      if(!result){
        return;
      }

      var parmDatas=[];
      for(PriceParm parm in parmPart.partParmList){
        var value=parm.value;
        // if(parm.required==1&&value.isEmpty){
        //   // result=false;
        //   // if(parm.type==0){
        //   //   ToastUtil.showToast('请输入${parm.name}');
        //   // }else{
        //   //   ToastUtil.showToast('请选择${parm.name}');
        //   // }
        //   // break;
        // }else{
        //   parmDatas.add({"name":parm.id,"value":value});
        // }
        parmDatas.add({"name":parm.id,"value":value});
      }
      if(!result){
        return;
      }



      bool isOk=true;
      List selects=[];
      for(var type in allDatas){
        if(!isOk)break;
        for(var brand in type.materialList){
          if(!isOk)break;
          for(var serial in brand.materialList){
            if(!isOk)break;
            for(var part in serial.materialList){
              if(!isOk)break;
              if(part.select){
                if(part.count==0){
                  ToastUtil.showToast("${part.name}请输入数量");
                  isOk=false;
                  break;
                }else{
                  selects.add({"id":part.id,"count":part.count});
                }
              }
            }
          }
        }
      }

      if(!isOk)return;
      if(selects.isEmpty){
        ToastUtil.showToast("请选择型号");
      }

      if(priceList.isNotEmpty&&supplierId.isEmpty){
        ToastUtil.showToast("请选择供应商");
      }


      var values = formKey.currentState!.value;
      var name=values["name"];
      var code=values["code"];
     // var dPrice=values["dPrice"];
      var tax=values["tax"];

      var area1=values["area1"];
      var area2=values["area2"];
      var weight1=values["weight1"];
      var weight2=values["weight2"];


      var s1=values["s1"];
      var s2=values["s2"];
      var h1=values["h1"];
      var h2=values["h2"];
      var e1=values["e1"];
      var e2=values["e2"];
      var w1=values["w1"];
      var w2=values["w2"];
      var d1=values["d1"];
      var d2=values["d2"];
      var c1=values["c1"];
      var c2=values["c2"];

      String jsonString = jsonEncode(specsList);
      var parm={
        "name":name,
        "code":code,
        "spec":jsonString,
        "parentId":widget.pricePart.parentId,
        "id":widget.pricePart.id,
        "dPrice":priceStr,
        "tax":tax,
        "remark":remarkDatas,
        "parm":parmDatas,
        "serialId":widget.pricePart.serialId,
        "area1":area1,
        "priceConfig":priceList,
        "supplierId":supplierId,
        "area2":area2,
        "weight1":weight1,
        "weight2":weight2,
        "config":selects,
        "s1":s1,
        "s2":s2,
        "h1":h1,
        "h2":h2,
        "e1":e1,
        "e2":e2,
        "w1":w1,
        "w2":w2,
        "d1":d1,
        "d2":d2,
        "c1":c1,
        "c2":c2,
      };
      BaseRequest.postHttp("price/editmatterial",parameters: parm, canTip: true, context: context, onSuccess: (data){
        bool result=BaseRequest.chekResponse(data, true);
        if(result){
          ToastUtil.showToast("编辑成功");
          eventBus.fire(EventRefreshBase());
          Navigator.pop(context);
        }
      }, onError: (error){

      });

    }
  }


  void getAllData(){
    BaseRequest.postHttp("price/baselist",parameters: {}, canTip: false , context: context, onSuccess: (data){
      bool result=BaseRequest.chekResponse(data, true);
      if(result){
        dynamic datas=data["data"];
        List allParts=[];
        for(var i=0;i<datas.length;i++){
          var item=datas[i];
          var part=PricePart.fromJson(item);
          allParts.add(part);
        }
        allDatas=allParts;
        initTreeDatas(allParts);
      }


    }, onError: (error){

    });
  }




  void initTreeDatas(List allParts){
    var trees=treeview.TreeNode.root();
    for(PricePart part in allParts){
      if(selectPricePart.name.isEmpty){
        selectPricePart=part;
      }
      part.path=part.id;
      treeview.TreeNode node= treeview.TreeNode(key: part.id,data:part);
      for(PricePart brand in part.materialList){

        brand.path="${part.id}.${brand.id}";
        treeview.TreeNode brandNode=treeview.TreeNode(key: brand.id,data: brand);

        for(PricePart serial in brand.materialList){

          serial.path="${part.id}.${brand.id}.${serial.id}";
          treeview.TreeNode serialNode=treeview.TreeNode(key: serial.id,data: serial);

          for(PricePart part in serial.materialList){
            if(hasSelect.containsKey(part.id)){
              var count=hasSelect[part.id];
              part.select=true;
              part.count=double.parse(count.toString());
            }else{
              part.select=false;
              part.count=1;
            }
          }
          brandNode.add(serialNode);
        }
        node.add(brandNode);
      }
      trees.add(node);

    }
    sampleTree=trees;
    updateRedPoint();



  }


  Widget allPartWidgets(){

    List<Widget> views=[];
    for(PricePart part in selectPricePart.materialList){
      views.add(SizedBox(height: ViewUtil.screenHeight(10),));
      views.add(Row(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          FlutterSwitch(value: part.select,
              width: 40.0,
              height: 25.0,
              onToggle: (value){
                part.select=value;
                updateRedPoint();
              }),
          SizedBox(width: ViewUtil.screenWidth(10),),
          Text(part.name),
          Expanded(child: Container()),
          Visibility(

              visible: part.select,
              child: SizedBox(width: 230,
                child: ShadInput(
                  textAlign: TextAlign.end,
                  initialValue: MathUtil.formatDouble(part.count, 2),
                  keyboardType: TextInputType.numberWithOptions(decimal: true),
                  inputFormatters: [
                    FilteringTextInputFormatter.allow(RegExp("[0-9.]")),
                    XNumberTextInputFormatter(
                        maxIntegerLength: null,
                        maxDecimalLength: 2,
                        isAllowDecimal: true),
                  ],
                  prefix: const Text('数量'),
                  placeholder: const Text('请输入数量'),
                  onChanged: (value){
                    part.count=double.parse(value);
                  },

                ),
              )),


        ],

      ));

      views.add(ViewUtil.lineView());
    }
    return Column(
      children: views,
    );
  }


  void initSelectData(){
    if(widget.pricePart.config.isNotEmpty){
      var config= jsonDecode(widget.pricePart.config);
      for(var item in config){
        var id=item["id"];
        var count=item["count"];
        hasSelect[id]=count;
      }
    }
  }


  getAllSelectData(){
    List<Widget> widgets=[];
    for(PricePart type in allDatas){
      bool hasAddType=false;
      for(PricePart brand in type.materialList){
        for(PricePart serial in brand.materialList){

          for(PricePart part in serial.materialList){
            if(part.select){
              if(!hasAddType){
                widgets.add(Text(type.name,style: TextStyle(fontSize: ViewUtil.fontSize(22),fontWeight: FontWeight.bold),),);
              }
              hasAddType=true;
              widgets.add(Row(
                children: [
                  const SizedBox(width: 10,),
                  Text(part.name,style: TextStyle(fontSize: ViewUtil.fontSize(22)),),
                  Expanded(child: Container()),
                  Text('数量:${MathUtil.formatDouble(part.count, 2)}',style: TextStyle(fontSize: ViewUtil.fontSize(22)),),
                ],
              ));
            }

          }
        }

      }
    }

    return widgets;
  }


  void updateRedPoint(){
    List<String> selectIds=[];
    for(PricePart type in allDatas){
      for(PricePart brand in type.materialList){
        for(PricePart serial in brand.materialList){
          for(PricePart part in serial.materialList){
            if(part.select){
              selectIds.add(type.id);
              selectIds.add(brand.id);
              selectIds.add(serial.id);
              selectIds.add(part.id);
            }
          }
        }

      }
    }
    hasSelectIds=selectIds;

    setState(() {

    });
  }



  getAllSupplier(){
    BaseRequest.postHttp('supplier/list', parameters: {"pageSize":"10000","page":'1'},
        canTip: false,
        context: context,
        onSuccess: (data) {
          bool result = BaseRequest.chekResponse(data, true);
          if (result) {
            dynamic records = data["data"]["records"];
            Map<String,Supplier> allModel = {};
            for (var i = 0; i < records.length; i++) {
              var item = records[i];
              var part = Supplier.fromJson(item);
              allModel[part.id]=part;
            }
            GlobalData.allSupplier=allModel;
            setState(() {

            });
          }
        },
        onError: (error) {

        });

  }

}
